require('./index.css');
require('page/common/nav/index.js');
require('page/common/header/index.js');
var _order = require('service/order-service.js');
var _mm = require('util/mm.js');
var navSide = require('page/common/nav-side/index.js');
var templateHtml = require('./index.string');
var Pagination = require('util/pagination/index.js');
var page = {
    data : {
        listParam : {
            pageNum : 1,
            pageSize : 10
        }
    },
    init : function(){
        this.onLoad();
    },
    onLoad : function(){
        this.loadOrderList();
        //初始化左侧菜单
        navSide.init({
            name : 'order-list'
        });
    },
    loadOrderList : function(){
        var _this = this,
            orderListHtml = '',
            $orderListCon = $('.order-list-con');
        _order.getOrderList(this.data.listParam,function(res){
            orderListHtml = _mm.renderHtml(templateHtml,res);
            $orderListCon.html(orderListHtml);
            _this.loadPagination({
                hasPreviousPage : res.hasPreviousPage,
                prePage : res.prePage,
                hasNextPage : res.hasNextPage,
                nextPage : res.nextPage,
                pageNum : res.pageNum,
                pages : res.pages
            });
        },function(errMsg){
            $orderListCon.html('<p class="err-tip">订单加载失败，请刷新后重试</p>')
        });
    },
    loadPagination : function(pageInfo){
        var _this = this;
        this.pagination ? '' : (this.pagination = new Pagination());
        this.pagination.render($.extend({},pageInfo,{
            container : $('.pagination'),
            onSelectPage : function(pageNum){
                _this.data.listParam.pageNum = pageNum;
                _this.loadOrderList();
            }
        }));
    }
};
$(function(){
    page.init();
});